<?php

class productTopComponents extends myComponents{
  
	public function executeRender(){
		$q = Doctrine_Query::create()
			->from('Product p')
			->select('p.*, pt.*, pp.*')
			->innerJoin('p.ProductGroups pgvp')
			->innerJoin('pgvp.ProductGroup pg WITH pg.parameter = ?', 'sales_top')
                        ->leftJoin('p.ProductPictures pp')
                        // Removed to avoid PG display in menu,
                        // check for structure is done with module connection
			//->innerJoin('pg.StructureProductGroup spg')
			//->innerJoin('spg.Structure s WITH s.id = ?', $this->getRoute()->getObject()->getId())
			->innerJoin('p.Translation pt WITH pt.lang = ? AND pt.name != ""', $this->getUser()->getCulture())
			->limit(10)
			->setHydrationMode(Doctrine::HYDRATE_ARRAY);

		$this->products = $q->execute();
		$this->productLinks = LinkGen::getInstance(LinkGen::PRODUCT)->collectionLinks($this->products);

	}
//	public function executeRender(){
//		$q = Doctrine_Query::create()
//			->from('ProductGroup pg')
//			->select('pg.*, pgt.* , pgvp.* , p.*, pp.*, pt.*')
//			->innerJoin('pg.Products pgvp')
//			->innerJoin('pgvp.Product p')
//			->where('pg.parameter = ?', 'index_page_group')
//			->innerJoin('pg.StructureProductGroup spg')
//			->leftJoin('p.ProductPictures pp')
//			->innerJoin('pg.Translation pgt WITH pgt.lang = ?', $this->getUser()->getCulture())
//			->innerJoin('spg.Structure s WITH s.id = ?', $this->getRoute()->getObject()->getId())
//			->innerJoin('p.Translation pt WITH pt.lang = ? AND pt.name != ""', $this->getUser()->getCulture())
//			->limit(5)
//			->setHydrationMode(Doctrine::HYDRATE_ARRAY);
//
//
//		$this->productGroups = $q->execute();
////		print_r($this->productGroups);
////		exit;
//		$productPKs = array();
//		foreach($this->productGroups as $group){
//			$c = 0;
//			foreach($group['Products'] as $product){
//				if($c == 3)break;
//				$productPKs[] = $product['Product'];
//				++$c;
//
//			}
//		}
//
//
//		$this->productLinks = LinkGen::getInstance(LinkGen::PRODUCT)->collectionLinks($productPKs);
//
//
//
//	}
}